data "alicloud_kms_plaintext" "main" {
  ciphertext_blob       = var.kms_encrypted_password
}

# resource "alicloud_kvstore_account" "main" {
#   account_name            = var.account_name
#   account_password        = var.account_password
#   kms_encrypted_password  = data.alicloud_kms_plaintext.main.ciphertext_blob
#   instance_id             = alicloud_kvstore_instance.main.id
# }

resource "alicloud_kvstore_instance" "main" {
  db_instance_name      = var.instance_name
  vswitch_id            = var.vswitch_id
  security_ips          = var.security_ips
  instance_type         = var.instance_type
  engine_version        = var.engine_version
  zone_id               = var.zone_id
  config                = var.config
  tags                  = var.tags
  security_group_id     = var.security_group_id
  instance_class        = var.instance_class
  password              = var.password
  kms_encrypted_password  = data.alicloud_kms_plaintext.main.ciphertext_blob
}

resource "alicloud_kvstore_backup_policy" "main" {
  instance_id   = alicloud_kvstore_instance.main.id
  backup_period = var.backend_period
  backup_time   = var.backup_time
}